//add(1)(2)(3)
const add = (a, b, c) => a + b + c;
// const add = x=>y=>z=>x+y+z;
// console.log(add(1)(2)(3))

// const curry = (fn, args = []) => {
//   const funcLength = fn.length;
//   return function () {
//     args = args.concat(Array.prototype.slice.call(arguments, 0));
//     if (args.length === funcLength) {
//       return fn.apply(fn, args);
//     }
//     return curry(fn, args);
//   };

// };
const curry = (fn, argsArr = []) => {
  const funcLength = fn.length;
  return (...args) => {
    let concatArgs = [...argsArr, ...args];
    if (concatArgs.length === funcLength) {
      return fn.apply(fn, concatArgs);
    }
    return curry(fn, concatArgs);
  };
};

console.log(curry(add)(1, 2)(3));
